import collections
class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def rightSideView(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        if not root:
            return None
        return_list = []
        now_layer = collections.deque([root])
        while now_layer:
            return_list.append(now_layer[-1].val)
            next_layer = collections.deque()
            for item in now_layer:
                if item.left:
                    next_layer.append(item.left)
                if item.right:
                    next_layer.append(item.right)
            now_layer = next_layer
        return return_list



